<script type="text/javascript">
	if (typeof jQuery == 'undefined'){
    document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script src="http://182.71.160.18/~sanchit/Pro7/js/calendar/calendar.js" type="text/javascript"></script>
<script src="http://182.71.160.18/~sanchit/Pro7/js/calendar/calendar-setup.js" type="text/javascript"></script>
<?php 
$customerid=Mage::getSingleton('customer/session')->getCustomerId();
$isPartner= Mage::getModel('marketplaceprofile/marketplaceprofile')->isPartner($customerid);
if($isPartner==1){?>
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/global.css'); ?>" rel="stylesheet" type="text/css" />


<style>
div.example-plot { height: 400px;width: 650px;}
.ctable{
 border-spacing: 0;    empty-cells: show;    font-size: 100%;}
.calendar{ background-color: white;cursor: pointer;  margin-left: 646px;    margin-top: 171px;    position: fixed !important;    z-index: 1100;}
#divid {
    border-bottom: 1px solid #F5F5F5;
    border-left: 1px solid #F5F5F5;
    border-right: 1px solid #F5F5F5;
    display: block;
   
    width: auto;
}
#ask-data1{background: none repeat scroll 0 0 #FCFCFC;border: 1px solid #D3C1C1;border-radius: 12px 12px 12px 12px;display: none;height: 120px;position: fixed;  width: 250px;top: 120px;left: 500px;z-index: 1050;}
#close{float:right; cursor: pointer; cursor: pointer;float: right;margin: 2px;}
#close:hover{color: #FC8B36;}
</style>
<?php echo $this->getChildHtml('html_calendar') ?>
<?php		
	$write = Mage::getSingleton('core/resource')->getConnection('core_write');
	$read = Mage::getSingleton('core/resource')->getConnection('core_read');
	$products = $this->getProducts();
	$page=$_GET['p'];
	if($page){
		$p=$page;
	}
	else{
		$p=1;
	}
	$numroww=Mage::getModel('marketplacepartner/Productsales')->getnumroww($customerid,$p);
	//print_r($numroww);
	$pagination = '';
	$readresult=Mage::getModel('marketplacepartner/Productsales')->getallOrderdetails($customerid,$p);
	$customerPartner = Mage::getModel('marketplacepartner/productsales');
	$getDateDetail = $customerPartner->getDateDetail();
	$cur_symbol=Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();

	$write = Mage::getSingleton('core/resource')->getConnection('core_write');
	$mysqlprefix = Mage::getConfig()->getTablePrefix();//code for mysql prefix
	
	//TO DO
	$sqlselect="SELECT mageproductid FROM ".$mysqlprefix."marketplacepartner_entity_data";
	$sqlselect1=$write->query($sqlselect);
	$sqlselectrow=$sqlselect1->fetchAll();
?>
<div class="prdouctbackground">
	<div class="maindash">
		<?php	$isThisEnabled = Mage::helper('core/data')->isModuleOutputEnabled('Webkul_Sellerstatus');
		if($isThisEnabled == 1){ ?>
		<span id="status" style="float:right; color: #246A52;cursor: pointer;"><?php echo Mage::helper('sellerstatus')->__('Click to download in PDF') ?></span>
		<?php } ?>
		<h4 class="textcolor"><?php echo Mage::helper('marketplacepartner')->__('Order History') ?></h4>
		    <div style="margin:10px;">
			<?php //print_r($numroww);
			if($numroww<=1)
			{}
			else{
			if($p > 1){
			$prev=$p-1;
				$pre =  Mage::helper('marketplacepartner')->__('Previous');
				$pagination .= '<a href="?p='.$prev.'">'.$pre.'</a> ';
			}
			if($p<=$numroww){
			for($i = ($p-1); $i <=($p+1); $i++){
				if($i==0){}
				else if($i==($numroww+1)){}
				else{
					if(($p) == $i){
						$pagination .= $i;
					}
					else{
						$pagination .= '<a href="?p='.$i.'"> '.$i.'</a> ';
					}
				}
			}
			}
			if($page< $numroww)
			{
			$next=$p+1;
			$nxt =  Mage::helper('marketplacepartner')->__('Next');
				$pagination .= '<a href="?p='.$next.'">'.$nxt.'</a>';
			}
			echo $pagination;
			}
			?>
			
			</div>
			<?php echo $this->getPagerHtml(); ?>
			<div class="orderdproduct">
			<div class="tablepostioneditdash ctable">
				<div id="divid">
					<?php
						$m=0;
						foreach($readresult as $res){
							$order = Mage::getModel('sales/order')->load($res['mageorderid']);
							$status=$order->getStatus();
							$name=$order->getCustomerName();
							if($res['mageorderid']>0){?>
								<div id="divid">
									<div class="tdpadfirsteditheadingdash" style="float:left;width:206px;">
										<label for="name" class="rightgapeditheadedit">
											<?php if($status=='pending') {?>
												<div class="status" style="background-color:orange"><?php echo strtoupper($status); ?> </div>
											<?php }?>
											<?php if($status=='canceled') {?>
												<div class="status" style="background-color:red"><?php echo strtoupper($status); ?> </div>
											<?php }?>
											<?php if($status=='complete') {?>
												<div class="status" style="background-color:green"><?php echo strtoupper($status); ?> </div>
											<?php }?>
											<?php if($status=='processing') {?>
												<div class="status" style="background-color:blue"><?php echo strtoupper($status); ?> </div>
											<?php }?>
											<p style="margin: 0 0 10px 6px;"><?php echo "<br>".$res['cleared_at']; ?></p> 
										</label> 
									</div>
									<div class="tdpadfirsteditheadingdash" style="float:left; width:206px;">
										<label for="name" class="rightgapeditheadedit">
											<div class="textcolordashdiv"><?php echo Mage::helper('marketplacepartner')->__('Order') ?> #<?php echo $res['magerealorderid']; ?></div>
											<div class="dd"><?php echo Mage::helper('marketplacepartner')->__('By') ?><?php  echo " ".$name; ?><br/>
											<?php
											  $pname=explode(',',$res['mageproname']);
											  $pid=explode(',',$res['mageproid']);
												for($p=0;$p<=count($pid);$p++){
												if($pname[$p]){
														echo "<p style='color:silver;float:left;'>".$pname[$p]."&nbsp;</p>"; $proid[$m]=$pid[$p];
														}
													
												}?>
											</div> 
										</label> 
									</div>
									<div class="tdpadfirsteditheadingdash" style="float:right;width:206px;">
										<label for="name" class="rightgapeditheadprice">$<?php echo $res['actualparterprocost'];?> </label> 
									</div>
								</div><div style="clear:both;"></div>
					<?php }
						} 
						?>	
								
				</div>
							
			</div>		
		</div>

		
	</div>
</div>

<div class="button-set buttonarea">
	<p class="headingbackindex">
		<a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo Mage::helper('marketplacepartner')->__('Back') ?></a>
	</p>
</div>
<div id="ask-data1">
	<div class="modal-header" style="padding:2px;">
		<span id="close">X</span><h3 style=" text-align: center;"><?php echo Mage::helper('marketplacepartner')->__('Select Date') ?></h3>
		<p style=" text-align: center;"><?php echo Mage::helper('marketplacepartner')->__('From') ?>:&nbsp;<input type="text" id="from" /></p> 
		<p style=" text-align: center;"><?php echo Mage::helper('marketplacepartner')->__('To') ?>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="to" /></p> 
		<p style=" text-align: center;"><button id="datebtn"><?php echo Mage::helper('marketplacepartner')->__('Download') ?></button></p>
	</div>
</div>
<script type="text/javascript">
$wk_jq=jQuery.noConflict();
$wk_jq(document).ready(function() {
	$wk_jq('body').append($wk_jq('#ask-data1'));
	Calendar.setup({
    inputField : 'from',
    ifFormat : '%Y-%m-%e',
    button : 'date_from_trig',
    align : 'Bl',
    singleClick : true
	});

	Calendar.setup({
	inputField : 'to',
	ifFormat : '%Y-%m-%e',
	button : 'date_to_trig',
	align : 'Bl',
	singleClick : true
	});
	$wk_jq('#status').click(function(){
		$wk_jq('.wrapper').css('opacity','0.4');
		$wk_jq('#ask-data1').css('opacity','1');
		$wk_jq('#ask-data1').show();
	});
	$wk_jq('#close').click(function(){
		$wk_jq('.wrapper').css('opacity','1');
		$wk_jq('#ask-data1').hide();
	});
	$wk_jq('#datebtn').click(function(){
			$wk_jq.ajax({
				url:'<?php echo Mage::getUrl('sellerstatus/adminhtml_sellerstatus/sellerstatus');?>',
				type: 'GET',
				data: {id:<?php echo Mage::getSingleton('customer/session')->getCustomer()->getId(); ?>,from:$wk_jq('#from').val(),to:$wk_jq('#to').val(),dir:"<?php echo Mage::getBaseDir();?>"},
				success:function(data){
					$wk_jq(".col-main").before($wk_jq('<span/>').text(data).addClass('message').css({color:'green'}));
					 setTimeout( "$wk_jq('.page').find('.message').fadeOut();",3000 );
				},
				error:function (){
					$wk_jq(".col-main").append($wk_jq('<span/>').text("<?php echo Mage::helper('marketplacepartner')->__('Unable to download File') ?>").addClass('message').css({color:'red'}));
					 setTimeout( "$wk_jq('.page').find('.message').fadeOut();",3000 );
				}
			});
			// $wk_jq( "#datepicker" ).datepicker();
			$wk_jq('.wrapper').css('opacity','1');
			 $wk_jq('#ask-data1').hide();
			 $wk_jq('#from').val('');
			 $wk_jq('#to').val('');
	});
});			
</script>
<?php }else{
	echo Mage::helper('marketplacepartner')->__("<h2 style='color:#ff0000;font-weight:600'>FOR BECOME SELLER CONTACT TO ADMIN..</h2>");
}?>